#include <iostream>
#include <string>


std::string solution(const std::string& s) {
    // PLEASE DO NOT MODIFY THE FUNCTION SIGNATURE
    // write code here
    if (s.empty())
        return ""; // Placeholder
    std::string ans(s);
    for(int i = ans.size()-1; i>=0; i--)
    {
        int flag = 0;
        for (int ii = 0; ii < ans.size(); ii++)
            if (ans[i] == 'a')
                flag = 1;
        if (flag)
        {
            size_t pos = s.rfind('a', i);
            ans.replace(pos, 1, "%100");
        }
    }
    return ans;
}

//int main() {
//    std::cout << (solution("abcdwa") == "%100bcdw%100") << std::endl;
//    std::cout << (solution("banana") == "b%100n%100n%100") << std::endl;
//    std::cout << (solution("apple") == "%100pple") << std::endl;
//    return 0;
//}